package com.sdry.product.waitingarea.controller;

import com.sdry.product.waitingarea.entity.ChoicePlan;
import org.springframework.ui.Model;
import com.sdry.basic.entity.Material;
import com.sdry.basic.service.MaterialService;
import com.sdry.common.BaseController;
import com.sdry.common.TableDataInfo;
import com.sdry.product.waitingarea.entity.StayContainerStare;
import com.sdry.product.waitingarea.service.StayContainerStareService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 备货计划绑定表
 * @Author chenBin
 * @Date 2020-03-27 14:45
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "stayContainerStare")
public class StayContainerStareController extends BaseController {

    @Resource
    private MaterialService materialService;

    @Resource
    private StayContainerStareService stayContainerStareService;

    /**
     * 展示备货计划
     * @return
     */
    @RequestMapping(value = "showChoicePlan")
    public String showChoicePlan(Model model) {
        Material param = new Material();
        List<Material> materialList = materialService.queryAllByMution(param);
        model.addAttribute("materialList",materialList);
        model.addAttribute("System",System.currentTimeMillis());
        return "/product/waitingarea/choicePlan";
    }

    /**
     * 备货计划添加
     * @param quantity 数量
     * @param maIds 产品ID
     * @param remark1 时间
     * @return
     */
    @RequestMapping(value = "/addChoicePlan")
    @ResponseBody
    public boolean addChoicePlan(
            String quantity,
            String maIds,
            String remark1,
            String plNumber
    ){
        try {
            return stayContainerStareService.addChoicePlan(quantity,maIds,remark1,plNumber);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 产品名称
     * @return
     */
    @RequestMapping(value = "queryMaterialList")
    @ResponseBody
    public List<Material> queryMaterialList() {
        Material param = new Material();
        List<Material> list = materialService.queryAllByMution(param);
        return list;
    }


    /**
     * 分页查询库存
     * @param stayContainerStare 对象
     * @return TableDataInfo
     */
    @RequestMapping(value = "/queryStayContainerStarePage")
    @ResponseBody
    public TableDataInfo queryStayContainerStarePage(StayContainerStare stayContainerStare) {
        List<StayContainerStare> stayContainerStareList = stayContainerStareService.queryStayContainerStarePage(stayContainerStare);
        Long total = stayContainerStareService.queryStayContainerStareTotal(stayContainerStare);
        return getDataTable(stayContainerStareList,total);
    }

    /**
     * 删除备货
     * @param plDeId 用户对象
     * @return String
     */
    @RequestMapping(value = "deleteStayContainerStare")
    @ResponseBody
    public Integer deleteStayContainerStare(Long plDeId) {
        return stayContainerStareService.deleteStayContainerStare(plDeId);
    }


    /**
     * 备货分页查询
     * @param stayContainerStare 对象
     * @return TableDataInfo
     */
    @RequestMapping(value = "/queryAddChoicePlanPage")
    @ResponseBody
    public TableDataInfo queryAddChoicePlanPage(StayContainerStare stayContainerStare) {
        List<ChoicePlan> choicePlanList = stayContainerStareService.queryAddChoicePlanPage(stayContainerStare);
        Long total = stayContainerStareService.queryAddChoicePlanTotal(stayContainerStare);
        return getDataTable(choicePlanList,total);
    }
}
